package main

import (
	"bufio"
	"fmt"
	"github.com/MingOf/logger"
	"github.com/MingOf/tcpSticky/proto"
	"net"
)

var log = logger.NewLogger("Info", "console", 0)

func process(conn net.Conn) {
	reader := bufio.NewReader(conn)
	//var buf = make([]byte, 128)
	var count int
	defer conn.Close()
	for {
		data, err := proto.Decode(reader)
		if err != nil {
			log.Error(err)
			break
		}
		count++
		fmt.Println(data)
	}
	fmt.Println("count", count)
}
func main() {
	listen, err := net.Listen("tcp", "127.0.0.1:20000")
	if err != nil {
		log.Error(err)
		return
	}
	defer listen.Close()
	for {
		conn, err := listen.Accept()
		if err != nil {
			log.Error(err)
			break
		} else {
			log.Info("connected")
		}
		go process(conn)
	}
}
